//
// Created by 下次一定 on 2021/9/6.
//
#include <iostream>

using namespace std;

// 栈  先进后出

// 队列  先进先出

int n;
const int N = 10010;
int stk[N] , tt;

int main() {
    cin.tie(0);
    cin >> n;
    for (int i = 0; i < n; i++){
        int x;
        cin >> x;
        while(tt && stk[tt] >= x) tt--;
        if(tt) cout << stk[tt] << " ";
        else cout << -1 << " ";
        stk[++tt] = x;
    }


}